package org.ocelot.tunes4j.taggers;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cmc.music.common.ID3ReadException;
import org.cmc.music.metadata.MusicMetadataSet;
import org.cmc.music.myid3.MyID3;
import org.ocelot.tunes4j.beans.AudioObject;





public class MyId3TaggerImpl implements Tagger {

	private Log log = LogFactory.getLog(this.getClass());
	
	@Override
	public AudioObject parse(File sourceFile) {
		AudioObject mp3Bean = null;

		mp3Bean = new AudioObject();
		mp3Bean.setPath(sourceFile.getParent());
		mp3Bean.setFileName(sourceFile.getName());
		MusicMetadataSet mp3file;
		try {
			mp3file = new MyID3().read(sourceFile);
			mp3Bean.setArtist(mp3file.merged.getArtist());
			mp3Bean.setTitle(mp3file.merged.getSongTitle());
			mp3Bean.setAlbum(mp3file.merged.getAlbum());
		} catch (ID3ReadException e) {
			System.out.println("Error en el archivo: " + sourceFile.getPath());
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("Error en el archivo: " + sourceFile.getPath());
			e.printStackTrace();
		}
		
		return mp3Bean;
	}

	@Override
	public void save(File sourceFile, AudioObject bean) {
		// TODO Auto-generated method stub
		
	}

}
